<!--
 * @Author: 杨超
 * @Date: 2021-11-24 20:33:45
 * @LastEditTime: 2021-11-30 11:55:15
 * @LastEditors: 杨超
 * @Description:
-->
<template>
    <!-- 普通输入框 -->
    <div :style="item.style || {}" :class="`form-unqiue-${item.key} ${getTextModel ? '' : 'wti-untext-box'}`" class="form-input-box form-item-box">
        <el-input
            v-if="!getTextModel"
            v-model.trim="val"
            :placeholder="getPlaceholder(item)"
            :disabled="getDisabled"
            type="text"
            :clearable="true"
            v-bind="bindOptions"
            @blur="(e) => onBlur(item, e)"
            @focus="(e) => onFocus(item, e)"
        >
            <template v-if="prepend" slot="prepend">
                <span v-if="item.prependSlot" v-html="prepend"></span>
                <span v-else>{{ prepend }}</span>
            </template>
            <template v-if="append" slot="append">{{ append }}</template>
        </el-input>
        <div v-else :style="item.textStyle || {}" class="form-input-text">
            <span v-if="prepend" class="prepend-msg">{{ prepend }}</span>
            <span class="text">{{ val || '-' }}</span>
            <span v-if="append" class="append-msg">{{ append }}</span>
        </div>
    </div>
</template>

<script>
import FormMixin from './mixin'

export default {
    name: 'FormInput',
    mixins: [FormMixin],
    computed: {
        // 前置符号
        prepend() {
            // 兼容性处理
            if (this.item.prepend) {
                return this.item.prepend
            } else if (this.item.prependMsg) {
                return this.item.prependMsg
            } else if (this.item.prefixMsg) {
                return this.item.prefixMsg
            } else {
                return ''
            }
        },
        // 后置符号
        append() {
            // 兼容性处理
            if (this.item.append) {
                return this.item.append
            } else if (this.item.appendMsg) {
                return this.item.appendMsg
            } else if (this.item.suffixMsg) {
                return this.item.suffixMsg
            } else {
                return ''
            }
        }
    }
}
</script>
